﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Functional
{
    public class Concatenations
    {
        public static List<T[]> UnConcatenate<T>(T[] inputs, int subVectorLength)
        {
            List<T[]> lOut = new List<T[]>();
            List<T> subVector;
            Int32 L1, L2, L3;
            L3 = 0;
            Int32 totalSubVectorsI = inputs.Length / subVectorLength;
            Double totalSubVectorsD;
            if (totalSubVectorsI * subVectorLength != inputs.Length)
            {
                totalSubVectorsD = Convert.ToDouble(inputs.Length) / Convert.ToDouble(subVectorLength);
                totalSubVectorsD = Math.Ceiling(totalSubVectorsD);
                totalSubVectorsI = Convert.ToInt32(totalSubVectorsD);
            }

            for (L1 = 0; L1 < totalSubVectorsI; L1++)
            {
                subVector = new List<T>();
                for (L2 = 0; L2 < subVectorLength; L2++)
                {
                    if (L3 >= inputs.Length)
                    {
                        break;
                    }
                    subVector.Add(inputs[L3]);
                    L3++;
                }
                //lOut[L1] = subVector;
                lOut.Add(subVector.ToArray());
            }
            return lOut;
        }

        public static T[] Concatenate<T>(List<T>[] input)
        {
            Int32 L;
            List<T> lOut = new List<T>();
            for (L = 0; L < input.Length; L++)
            {
                lOut.AddRange(input[L]);
            }
            return lOut.ToArray();
        }
    }
}
